import api from './index'

export interface LoginRequest {
  username: string
  password: string
}

export interface RegisterRequest {
  username: string
  password: string
  name?: string
  email?: string
  role?: string
}

export interface BatchRegisterRequest {
  students: Array<{
    username: string
    password?: string
    name: string
    email?: string
  }>
}

export interface User {
  id: number
  username: string
  role: string
  created_at: string
}

export interface LoginResponse {
  token: string
  token_type: string
  user: User
}

export const authApi = {
  // 登录
  login(data: LoginRequest): Promise<LoginResponse> {
    return api.post('/auth/login', data)
  },

  // 注册
  register(data: RegisterRequest): Promise<User> {
    return api.post('/auth/register', data)
  },

  // 注册管理员账号
  registerAdmin(data: RegisterRequest): Promise<User> {
    return api.post('/auth/register-admin', data)
  },

  // 获取用户信息
  getProfile(): Promise<User> {
    return api.get('/auth/profile')
  },

  // 修改密码
  changePassword(data: { old_password: string; new_password: string }): Promise<void> {
    return api.post('/auth/change-password', data)
  },

  // 批量注册学生账号
  registerBatch(data: BatchRegisterRequest): Promise<any> {
    return api.post('/auth/register-batch', data)
  }
}
